package com.neu.common.utils;

import com.neu.common.constant.ResultCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result {
    private Integer code;
    private String message;
    private Object data;

    public static Result ok(){
        return new Result(ResultCodeEnum.SUCCESS_CODE.getCode(), ResultCodeEnum.SUCCESS_CODE.getMessage(), null);
    }

    public static Result error(){
        return new Result(ResultCodeEnum.FAIL_CODE.getCode(), ResultCodeEnum.FAIL_CODE.getMessage(), null);
    }

    public Result put(Object data){
        this.data = data;
        return this;
    }

    public Result setMessage(String message){
        this.message = message;
        return this;
    }

    public Result setCode(Integer code){
        this.code = code;
        return this;
    }

    public Result setCodeAndMessage(ResultCodeEnum resultCodeEnum){
        this.code = resultCodeEnum.getCode();
        this.message = resultCodeEnum.getMessage();
        return this;
    }
}
